package com.hong.course.filter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
import org.springframework.stereotype.Component;
/**
 * 描述：前置过滤器
 */
@Component
public class PreRequestFilter extends ZuulFilter {

    @Override
    public String filterType() {
        return FilterConstants.PRE_TYPE; // 前置过滤器
    }

    @Override
    public int filterOrder() {
        return 5; // 优先级为5，数字越大，优先级越低
    }

    @Override
    public boolean shouldFilter() {
        return true;
    }

    @Override
    public Object run() throws ZuulException {
        // 该方法中可以实现自定义的过滤逻辑
        RequestContext ctx = RequestContext.getCurrentContext();
        System.out.println("进入了前置过滤器");
        System.out.println("URI:" + ctx.getRequest().getRequestURI());
        return null;
    }
}
